import java.util.List;

public class MyQueue1 implements IQueue{
    //用单链表实现队列

    static class ListNode {
        public int val;
        public ListNode next;

        public ListNode(int val) {
            this.val = val;
        }
    }
    public ListNode head;//入队位置
    public ListNode last;//出队位置


    @Override
    public void offer(int val) {
        //入队--尾插
        ListNode node = new ListNode(val);
        if(last == null) {
            head = node;
            last = node;
            return;
        }
        last.next = node;
        last = node;
    }

    @Override
    public int poll() {
        //出队，头删
        if(head == null) {
            return -1;
        }
        int tmp = head.val;
        head = head.next;
        return tmp;
    }

    @Override
    public int peek() {
        //查看队头元素
        if(head == null) {
            return -1;
        }
        int tmp = head.val;
        return tmp;
    }

    @Override
    public int size() {
        int count = 0;
        ListNode cur = head;
        while(cur != null) {
            count++;
            cur = cur.next;
        }
        return count;
    }

    @Override
    public boolean isEmpty() {
        return head==null;
    }

    @Override
    public void display() {
        ListNode cur = head;
        while(cur != null) {
            System.out.print(cur.val+" ");
            cur = cur.next;
        }
        System.out.println();
    }
}
